import 'dart:typed_data';

import 'package:app_updater/app_updater.dart';
import 'package:app_updater/entity/download_status.dart';
import 'package:app_updater/updater_method_channel.dart';
import 'package:app_updater/updater_platform_interface.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';

class MockAppUpdaterPlatform
    with MockPlatformInterfaceMixin
    implements AppUpdaterPlatform {
  @override
  Future<String?> getPlatformVersion() => Future<String>.value('42');

  @override
  Future<int> enqueueDownload({
    required String url,
    String? localPath,
    Map<String, String>? headers,
    String? title,
    String? description,
  }) {
    return Future<int>.value(0);
  }

  @override
  Future<int> removeDownload(List<int> ids) {
    return Future<int>.value(ids.length);
  }

  @override
  Future<DownloadStatus?> getDownloadStatus(int id) {
    return Future<DownloadStatus?>.value();
  }

  @override
  Future<Uri?> getUriForDownloadedFile(int id) {
    return Future<Uri?>.value();
  }

  @override
  Future<Uint8List> calculateMD5Checksum(int id) {
    return Future<Uint8List>.value(Uint8List(0));
  }

  @override
  Future<void> requestInstallAPK(String uriString) {
    return Future<void>.value();
  }
}

void main() {
  final AppUpdaterPlatform initialPlatform = AppUpdaterPlatform.instance;

  test('$MethodChannelAppUpdater is the default instance', () {
    expect(initialPlatform, isInstanceOf<MethodChannelAppUpdater>());
  });

  test('getPlatformVersion', () async {
    final AppUpdater appUpdaterPlugin = AppUpdater();
    final MockAppUpdaterPlatform fakePlatform = MockAppUpdaterPlatform();
    AppUpdaterPlatform.instance = fakePlatform;

    expect(await appUpdaterPlugin.getPlatformVersion(), '42');
  });
}
